<?php
header('Content-type: application/json;charset=utf-8');
require_once(dirname(__FILE__) . '/../../inc/config.inc.php');
IsModelPriv('goodsorder');
$tbname = '#@__task';
//引入操作类
$field = isset($_POST['field']) ? $_POST['field'] : [];
$title = empty($field['title']) ? "" : $field['title'];
$classid = isset($field['classid']) ? intval($field['classid']) : 0;
$value = isset($field['value']) ? intval($field['value']) : 0;
$picurl = empty($field['picurl']) ? "" : htmlspecialchars($field['picurl']);
$unit = empty($field['unit']) ? "" : htmlspecialchars($field['unit']);
$remark = empty($field['remark']) ? "" : htmlspecialchars($field['remark']);
$orderid = empty($field['orderid']) ? 0 : intval($field['orderid']);
$action = empty($_POST['action']) ? "" : htmlspecialchars($_POST['action']);



//审核状态
if (!isset($field['checkinfo'])) {
    $checkinfo = 0;
} else {
    $checkinfo = 1;
}

$time=time();

if ($action == 'update') {
    $id = empty($field['id']) ? 0 : intval($field['id']);
    if($classid==0 ||$value==0 || $title=="" || $id==0 ){
        $row_arr['code'] = -1;
        $row_arr['msg'] = "参数错误";
        echo json_encode($row_arr);
        exit;

    }
    $dosql->ExecNoneQuery("UPDATE $tbname SET classid='$classid',title='$title',orderid='$orderid',picurl='$picurl',`checkinfo`='$checkinfo',updatetime='$time',`value`='$value',unit='$unit',remark='$remark' WHERE id=$id");

    $row_arr['code'] = 0;
    $row_arr['msg'] = "编辑成功";
    echo json_encode($row_arr);
}
if ($action == 'add') {

    if($classid==0 ||$value==0 || $title=="" ){
        $row_arr['code'] = -1;
        $row_arr['msg'] = "参数错误";
        echo json_encode($row_arr);
        exit;
    }

    $dosql->ExecNoneQuery("INSERT INTO $tbname (`classid`,`title`,`checkinfo`,`orderid`,`picurl`,`addtime`,`remark`,`value`,`unit`) VALUES ('$classid','$title','$checkinfo','$orderid','$picurl','$time','$remark','$value','$unit')");

    $row_arr['code'] = 0;
    $row_arr['msg'] = "添加成功";
    echo json_encode($row_arr);

}
if ($action == 'del') {
    $id = empty($_POST['id']) ? 0 : intval($_POST['id']);
    $dosql->ExecNoneQuery("UPDATE $tbname  SET is_delete='1',deletetime='$time' WHERE id=$id ");
    $row_arr['code'] = 0;
    $row_arr['msg'] = "删除成功";
    echo json_encode($row_arr);
}